#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/completion.h>
#include <linux/kthread.h>
#include <linux/fs.h>

#include <linux/module.h>
#include <linux/irq.h>
#include <linux/platform_device.h>
#include <linux/dma-mapping.h>
#include <linux/cdev.h>
#include <linux/types.h>
#include <linux/mutex.h>
#include <linux/acpi.h>
#include <crypto/internal/hash.h>
#include <linux/crypto.h>
#include <crypto/hash.h>
#include <crypto/internal/skcipher.h>
#include <crypto/internal/akcipher.h>
#include <linux/ioport.h>
#include <linux/io.h>

#include "test.h"

u32 idx;
char *alg;
u32 step;
u32 sync;

module_param(alg, charp, 0);
module_param(idx, uint, 0);
module_param(step, uint, 0);
module_param(sync, uint, 0);

void print_buf(u8 *name, u8 *buf, u32 len)
{
	u32 i;

	pr_err("%s[0x%x]:\n", (char *)name, len);
	for (i = 0; i < len; i += 16) {
		pr_err("%08x: %02x %02x %02x %02x %02x %02x %02x %02x "
		       "%02x %02x %02x %02x %02x %02x %02x %02x\n",
		       i, buf[i + 0], buf[i + 1], buf[i + 2], buf[i + 3],
		       buf[i + 4], buf[i + 5], buf[i + 6], buf[i + 7],
		       buf[i + 8], buf[i + 9], buf[i + 10], buf[i + 11],
		       buf[i + 12], buf[i + 13], buf[i + 14], buf[i + 15]);
	}
}

static int __init sm_test_init(void)
{
	if (alg == NULL) {
		pr_err("Invalid alg(null)\n");
		return -EINVAL;
	}

	if (strcmp(alg, "sm3") == 0) {
		// alg = "sm33-test";
		sm3_test();
	} else if (strcmp("hmac(sm3)", alg) == 0) {
		hmac_sm3_test();
	} else if (strcmp("sm2", alg) == 0) {
		sm2_test();
	} else if (strcmp("ecb(sm4)", alg) == 0) {
		sm4_test(0);
	} else if (strcmp("cbc(sm4)", alg) == 0) {
		sm4_test(1);
	} else if (strcmp("ctr(sm4)", alg) == 0) {
		sm4_test(2);
	} else {
		pr_err("Invalid alg(null)\n");
		return -EINVAL;
	}

	return -1;
}

/*
 * If an init function is provided, an exit function must also be provided
 * to allow module unload.
 */
static void __exit sm_test_exit(void)
{
}

module_init(sm_test_init);
module_exit(sm_test_exit);

MODULE_LICENSE("GPL");